from flask import g
from flask_restful import Resource
from sqlalchemy.orm import load_only

from models.user import User
from utils.decorators import login_required

class CurrentUserResource(Resource):
    method_decorators = {'get':[login_required]}

    def get(self):
        userid = g.userid
        user = User.query.options(load_only(User.id,User.name,User.profile_photo,User.introduction,
                                           User.article_count,User.following_count)).filter(User.id == userid).first()

        return user.to_dict()